package com.htzz.collection.domain;

import com.htzz.collection.config.SystemConfig;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author xudezhi
 * @title: ResultVO
 * @projectName collection
 * @description: 查询接口响应类
 * @date 2021/8/2714:01
 */
@ApiModel(value = "查询接口响应类",description = "查询接口响应类")
@Data
public class ResultVO {

    @ApiModelProperty(value="响应码",example = "200")
    private Integer code;

    @ApiModelProperty(value="响应消息",example = "success")
    private String msg;

    @ApiModelProperty(value="是否成功",example = "true")
    private boolean success;

    @ApiModelProperty(value="响应对象",example = "json类型对象")
    private Object data;

    public static ResultVO error() {
        return error(SystemConfig.EXCEPTION);
    }

    public static ResultVO error(String msg) {
        ResultVO r = new ResultVO();
        r.setCode(SystemConfig.EXCEPTION.getCode());
        r.setMsg(msg);
        r.setSuccess(false);
        return r;
    }

    public static ResultVO error(SystemConfig rcode) {
        ResultVO r = new ResultVO();
        r.setCode(rcode.getCode());
        r.setMsg(rcode.getMsg());
        r.setSuccess(false);
        return r;
    }

    public static ResultVO ok() {
        ResultVO r = new ResultVO();
        r.setCode(SystemConfig.SUCCESS.getCode());
        r.setMsg(SystemConfig.SUCCESS.getMsg());
        r.setSuccess(true);
        return r;
    }

    public static ResultVO ok(Map<String, Object> map) {
        ResultVO r = new ResultVO();
        r.setCode(SystemConfig.SUCCESS.getCode());
        r.setMsg(SystemConfig.SUCCESS.getMsg());
        r.setData(map);
        r.setSuccess(true);
        return r;
    }

}
